import './api/api_client.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'bindings/app_routes.dart';

import 'utils/is_session_valid.dart';

Future<void> main() async {
  WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
  FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);

  WidgetsFlutterBinding.ensureInitialized(); // 初始化
  ApiClient.init(); // 初始化 API 客户端

  final islogin = await isSessionValid(); // 判断是否登录

  runApp(MyApp(islogin: islogin));
}

class MyApp extends StatelessWidget {
  final bool islogin;

  const MyApp({super.key, required this.islogin});

  @override
  Widget build(BuildContext context) {
    FlutterNativeSplash.remove();
    return GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: '验证登陆状态',
      theme: ThemeData(
        // 取消水波纹效果
        splashColor: Color.fromRGBO(0, 0, 0, 0),
        highlightColor: Color.fromRGBO(0, 0, 0, 0),
      ),
      defaultTransition: Transition.cupertino,
      initialRoute: islogin ? AppRoutes.tabs : AppRoutes.login, // 使用抽离的路由常量
      getPages: AppRoutes.routes, // 使用抽离的路由配置
    );
  }
}
